import { BasicColumn, FormSchema } from '@/components/Table';
import { h, ref } from 'vue';
import { Tag } from 'ant-design-vue';
import { ywUserSelectList } from '@/api/heng/ywManage';
import { ApiSelect } from '@/components/Form';
import util from '@/utils/util';

import { useMessage } from '@/hooks/web/useMessage';
import Ainput from '@/views/bookManage/components/account/Ainput.vue';
import { VxeFormItemProps, VxeGridPropTypes } from '@/components/VxeTable';
import { changeEnd } from 'codemirror';

type CheckedType = boolean | string | number;
// BasicColumn[]

// VxeColumnPropTypes.CellRender

/**
 */
export const vxeTableColumns: VxeGridPropTypes.Columns = [
  {
    title: '审批编号',
    field: 'approveNo',
    showOverflow: 'title',
    filters: [{ data: '' }],
    filterRender: {
      name: 'VxeInput',
    },
    formatter: ({ cellValue, row, column }) => {
      let val = cellValue;
      if (!row.stateName) {
        return val;
      }
      val = `${val}(${row.stateName})`;
      return val;
    },

    // width: 130,
  },

  {
    title: '申请时间',
    field: 'createTime',
    showOverflow: 'title',
    align: 'center',
    width: 140,
  },

  {
    title: '发起人',
    field: 'userName',
    align: 'center',
    width: 70,
  },
  {
    title: '审批状态',
    field: 'state',
    slots: { default: 'state' },
    align: 'center',
    width: 100,
  },
  {
    width: 230,
    title: '操作',
    align: 'center',
    field: '',
    slots: { default: 'action' },
    fixed: 'right',
  },
];

export const vxeTableFormSchema: VxeFormItemProps[] = [
  {
    span: 5,
    field: 'keyword',
    title: '查询',
    itemRender: {
      props: {
        placeholder: '审批编号，申请人',
      },
      name: 'AInput',
    },
  },
  {
    span: 5,
    field: 'state',
    title: '审批状态',
    itemRender: {
      name: 'ASelect',
      // defaultValue: 9999,
      props: {
        options: [
          { label: '审批中', value: 'RUNNING' },
          { label: '已通过', value: 'PASSED' },
          { label: '已驳回', value: 'REJECTED' },
          { label: '已撤销', value: 'CANCELED' },
          { label: '退回到发起人', value: 'BACKTOSTART' },
        ],
      },
    },
  },
  {
    span: 5,
    itemRender: {
      name: 'VxeButtonGroup',
      options: [
        { type: 'reset', content: '重置' },
        { type: 'submit', content: '查询', status: 'primary' },
      ],
    },
  },
];

export const rules = {
  mouldNameObj: [{ required: true, message: '费用名称不能为空', trigger: 'change' }],
  materialNo: [
    { required: true, message: '物料编号不能为空', trigger: 'change' },
    { min: 3, max: 5, message: 'Length should be 3 to 5', trigger: 'blur' },
  ],
  orderNo: [
    { required: true, message: '采购单号不能为空', trigger: 'change' },
    { min: 3, max: 5, message: 'Length should be 3 to 5', trigger: 'blur' },
  ],
};

/**
 * 审批列表
 */

export const confirmColumns: VxeGridPropTypes.Columns = [
  {
    title: '单据来源编号',
    field: 'orderNo',
    showOverflow: 'title',
    width: 130,
  },
  {
    title: '类型',
    field: 'type',
    showOverflow: 'title',
    align: 'center',
    width: 100,
  },

  {
    title: '抽成比例',
    field: 'orderCommissionRate',
    formatter: ({ cellValue, row, column }) => `${cellValue ? cellValue + '%' : ''}`,
    showOverflow: 'title',
    width: 100,
  },
  {
    title: '人民币总金额',
    field: 'totalAllPrice',
    slots: {
      footer: 'footer_totalAllPrice',
    },
    align: 'center',
    width: 100,
  },
  {
    title: '抽成金额',
    field: 'orderCommissionPrice',
    formatter: ({ cellValue, row, column }) => `${cellValue ? cellValue + '元' : ''}`,
    slots: {
      footer: 'footer_orderCommissionPrice',
    },
    showOverflow: 'title',
    width: 100,
  },

  {
    title: '接单人',
    field: 'receiverUserName',
    align: 'center',
    width: 100,
  },
  {
    title: '接单人抽成金额',
    field: 'receiverUserPrice',
    // formatter: ({ cellValue, row, column }) => `${cellValue ? cellValue + '元' : ''}`,
    slots: {
      footer: 'footer_receiverUserPrice',
    },
    align: 'center',
    width: 100,
  },

  {
    title: '跟单人',
    field: 'merchandiserUserName',
    align: 'center',
    width: 100,
  },
  {
    title: '跟单人抽成金额',
    field: 'merchandiserUserPrice',
    // formatter: ({ cellValue, row, column }) => `${cellValue ? cellValue + '元' : ''}`,
    slots: {
      footer: 'footer_merchandiserUserPrice',
    },
    align: 'center',
    width: 100,
  },
  {
    title: '介绍人',
    field: 'introduceUserName',
    align: 'center',
    width: 60,
  },
  {
    title: '介绍人抽成',
    field: 'introduceUserPrice',
    align: 'center',
    width: 60,
    // formatter: ({ cellValue, row, column }) => `${cellValue ? cellValue + '元' : ''}`,
  },
  {
    title: '业务经理',
    field: 'manageUserName',
    align: 'center',
    width: 70,
  },
  {
    title: '经理抽成',
    field: 'manageUserPrice',
    // formatter: ({ cellValue, row, column }) => `${cellValue ? cellValue + '元' : ''}`,
    slots: {
      footer: 'footer_manageUserPrice',
    },
    align: 'center',
    width: 90,
  },
  {
    title: '项目组',
    field: 'xiangMuGroupName',
    align: 'center',
    width: 70,
  },
  {
    title: '项目组抽成',
    field: 'xiangMuGroupPrice',
    // formatter: ({ cellValue, row, column }) => `${cellValue ? cellValue + '元' : ''}`,
    slots: {
      footer: 'footer_xiangMuGroupPrice',
    },
    align: 'center',
    width: 90,
  },
  {
    title: '团建基金',
    field: 'jiJingName',
    width: 100,
  },
  {
    title: '团建金额',
    field: 'jiJingPrice',
    width: 100,
    slots: {
      footer: 'footer_jiJingPrice',
    },
  },
];
